Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THREESCALE-11498: API plans features #3949

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jlledom
Copy link
Contributor

@jlledom jlledom commented Nov 28, 2024

What this PR does / why we need it:

The plan features API is a bit messy. For instance, AFAIK there's no endpoints to create or remove features for a plan, they must be created and deleted from the UI. The API only allows enabling or disabling features previously created from the UI. These are the endpoints:

  1. GET /admin/api/account_plans/:account_plan_id/features(.:format)
    • Returns the enabled features
  2. POST /admin/api/account_plans/:account_plan_id/features(.:format)
    • Enables a feature
    • It must receive feature_id as query param or form data
    • Returns 200 on success
    • Returns 409 when the feature was already enabled
    • Returns 404 when the plan doesn't exist or the plan exists but the feature doesn't exists for that plan
  3. DELETE /admin/api/account_plans/:account_plan_id/features/:id(.:format)
    • Disables a feature
    • Takes the feature ID from the path, not in parameters like in the enabling endpoint
    • 200 on success
    • 404 when the endpoint was already disabled
    • 404 when the plan doesn't exists or the feature doesn't exist for the plan

I find this inconsistent and confusing. I guess we need to keep it as it is to avoid breaking changes, but it'd be good if we create a new API for this, at some point... in the future...

In this PR I'm making a few changes:

  1. I renamed a scope and rewrote some comments to make clear in the code which association returns all available features and which one only returns the enabled ones: a5d6b40
  2. I fixed the Open API spec for Account Plans Features endpoints. It was wrong and it included a new endpoint which doesn't exist: POST /admin/api/account_plans/:account_plan_id/features/:id(.:format)
    I modified to be POST /admin/api/account_plans/:account_plan_id/features which exists and it's the correct one to enable features. d1b1d00
  3. I also renamed the same endpoints for Service and Application plans, to explicitly mention enabling and disabling: 60739a7

Which issue(s) this PR fixes

https://issues.redhat.com/browse/THREESCALE-11498

previous name was hard to understand, and incorrect, since features may
belong to service or account plans
@jlledom jlledom self-assigned this Nov 28, 2024
@jlledom jlledom force-pushed the THREESCALE-11498-api-features-plans branch from 1c4bdef to a5d6b40 Compare November 29, 2024 09:19
@jlledom jlledom changed the title Threescale 11498 api features plans THREESCALE-11498: API plans features Nov 29, 2024
@jlledom jlledom marked this pull request as ready for review November 29, 2024 11:58
"post": {
"summary": "Account Plan Features Create",
"description": "Associate an account feature to an account plan.",
"summary": "Account Plan Features Enable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"summary": "Account Plan Features Enable",
"summary": "Account Plan Feature Enable",

Maybe this to clarify further that it is for a single feature.

"delete": {
"summary": "Account Plan Features Delete",
"description": "Deletes the association of an account feature to an account plan.",
"summary": "Account Plan Features Disable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"summary": "Account Plan Features Disable",
"summary": "Account Plan Feature Disable",

@mayorova
Copy link
Contributor

The plan features API is a bit messy. For instance, AFAIK there's no endpoints to create or remove features for a plan, they must be created and deleted from the UI. The API only allows enabling or disabling features previously created from the UI.

I believe this is not accurate.

There is actually a set of endpoints under "Service Features" section that allows managing application plans features (creating new ones, updating, deleting etc.)

image

I'm not sure about features for service and account plans though...

@mayorova
Copy link
Contributor

OK, so for account plan features it seems that there are also endpoints for CRUD:
image

But I can't find the same for the service plan features 😬

mayorova
mayorova previously approved these changes Dec 12, 2024
@jlledom
Copy link
Contributor Author

jlledom commented Dec 18, 2024

@mayorova I applied your suggestions 6afe150

There is actually a set of endpoints under "Service Features" section that allows managing application plans features
OK, so for account plan features it seems that there are also endpoints for CRUD:

So, service features are created and enabled by:

/admin/api/services/{service_id}/features.xml
/admin/api/service_plans/{service_plan_id}/features.xml

Account features are created and enabled by:

/admin/api/features.xml
/admin/api/account_plans/{account_plan_id}/features.xml

Application features can only be created from UI and enabled by:
/admin/api/application_plans/{application_plan_id}/features.xml

I love porta consistency.

has_many :features, :through => :features_plans do
# returns all features owned by issuer, not only enabled by plan
def of_service
has_many :features_plans, as: :plan, dependent: :delete_all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add dependent: :delete_all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember, but it was a good reason, for sure!

It makes sense, though. features_plans is a N-N table between features and plans, and every record represents a feature enabled for a plan. It makes no sense to keep a feature enabled for a plan after the plan is removed.

Copy link
Contributor

@akostadinov akostadinov Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many of them can there be? We split deleting for transactions failing reason when they are too big. That's why we have the background deletion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan having more features has 88. I don't think that's usual though, probably most of them have less than 10. Also, the association between features and features_plans is marked as dependent: :delete_all as well:

has_many :features_plans, :dependent => :delete_all

@mayorova
Copy link
Contributor

So, service features are created and enabled by:

/admin/api/services/{service_id}/features.xml /admin/api/service_plans/{service_plan_id}/features.xml

Account features are created and enabled by:

/admin/api/features.xml /admin/api/account_plans/{account_plan_id}/features.xml

Application features can only be created from UI and enabled by: /admin/api/application_plans/{application_plan_id}/features.xml

I love porta consistency.

Not exactly 😅

/admin/api/services/{service_id}/features.xml is for managing the Application plan features.

It's endpoints for Service plans features CRUD that are missing, and can only be done via UI.

@jlledom
Copy link
Contributor Author

jlledom commented Dec 18, 2024

So, service features are created and enabled by:
/admin/api/services/{service_id}/features.xml /admin/api/service_plans/{service_plan_id}/features.xml
Account features are created and enabled by:
/admin/api/features.xml /admin/api/account_plans/{account_plan_id}/features.xml
Application features can only be created from UI and enabled by: /admin/api/application_plans/{application_plan_id}/features.xml
I love porta consistency.

Not exactly 😅

/admin/api/services/{service_id}/features.xml is for managing the Application plan features.

It's endpoints for Service plans features CRUD that are missing, and can only be done via UI.

Ah, I was so wrong, so the application features are created through the services endpoint, and there's no endpoint for services. Nice, much better! 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants